<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{{title}}</title>
    <link rel="stylesheet" href="stylesheets/bootstrap.min.css">
    <link rel="stylesheet" href="stylesheets/base.css">
    <link rel="stylesheet" href="stylesheets/index.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
</head>

<body>
    <div class="login bg-primary">
        <form class="form-horizontal" role="">
            <div class="form-group">
                <label for="username" class="col-sm-2 col-md-2 control-label">用户名</label>
                <div class="col-sm-10 col-md-10">
                    <input type="text" class="form-control" id="username" placeholder="请输入名字">
                </div>
            </div>
            <div class="form-group">
                <label for="userpwd" class="col-sm-2 col-md-2 control-label">密码</label>
                <div class="col-sm-10 col-md-10">
                    <input type="text" class="form-control" id="userpwd" placeholder="请输入姓">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10 col-md-offset-2 col-md-10">
                    <button type="submit" class="btn btn-default" id="submit">登录</button>
                </div>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        $(function() {
            $('#submit').on('click', function() {
                var username = $('#username').val(),
                    userpwd = $('#userpwd').val();
                $.ajax({
                    type: 'post',
                    url: '/user',
                    data: {
                        user: username,
                        pwd: userpwd
                    },
                    success: function(res) {
                        if (res == '用户不能为空！') {
                            alert(res)
                            return false;
                        }
                        if (res == '用户不存在！') {
                            alert(res)
                            return false;
                        }
                        if (res == 1) {
                            alert('用户名正确！')
                            location.href = '/user/main';
                        }
                    },
                    error: function(err) {

                    }
                })
            })
        })
    </script>
</body>

</html>

</html>